<%--
  Created by IntelliJ IDEA.
  User: cos
  Date: 2021/11/17
  Time: 15:18
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
</head>
<body>
<h1>login</h1>

<form action="#">
    用户名: <input type="text"> <br>
    密码: <input type="text"> <br>
    手机号: <input type="text" id="phone"> &nbsp; <button id="sendCode"  >发送验证码</button>
</form>
<script>
    var timer ;
    var num=5;

    $(function () {
        $("#sendCode").click(function () {
            $.ajax({
                url:"/emp/getCode?phone="+$("#phone").val(),
                success:function (result) {
                    if (result=='OK') {
                        // $("#sendCode").attr("disabled");
                        $("#sendCode").prop("disabled",true);
                        timer=setInterval(countDown,"1000");
                    }
                }
            })
        })
    })
    function countDown(){
        num--;
        if (num!=0) {
            $("#sendCode").text(num);
            // $("#sendCode").val(num);
        }else{
            clearInterval(timer);
            // $("#sendCode").removeAttribute("disabled");
            $("#sendCode").prop("disabled",false);
            $("#sendCode").text("发送验证码");
            num=60;
        }
    }
</script>


</body>
</html>
